<template>
  <el-form>
    <el-form-item label="登录用户名">
      <el-input v-model.trim="user.username" />
    </el-form-item>
    <el-form-item label="原密码">
      <el-input type="password" v-model.trim="oldPsw" />
    </el-form-item>
    <el-form-item label="新密码">
      <el-input type="password" v-model.trim="newPsw" />
    </el-form-item>
    <el-form-item label="确认新密码">
      <el-input type="password" v-model.trim="comfirmPsw" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submit">Update</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          username: '',
        }
      }
    }
  },
  data(){
    return{
      oldPsw:'',
      newPsw:'',
      comfirmPsw:''
    }
  },
  methods: {
    submit() {
      if(this.newPsw!==this.comfirmPsw){
        this.$message.warning("两次密码不一致，请重新输入！")
      }else{
        this.postRequest('/info/encode?newPsw='+this.newPsw+'&oldPsw='+this.oldPsw+'&userId='+this.user.id).then(resp=>{
          console.log(resp)
          if (resp && resp.obj===null){
            new Promise((resolve) => setTimeout(resolve, 1000)).then(()=>{
              this.$router.replace('/')
            }
            )
          }
        })
      }

    }
  }
}
</script>
